home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / term43-source.lha / Extras / Source / term-Source.lha / termDial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-20  |  36.3 KB  |  1,730 lines

  1. /*
  2. **    termDial.c
  3. **
  4. **    The dialing routine as called by the phonebook
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #include "termGlobal.h"
  13.  
  14.     /* Panel gadget IDs. */
  15.  
  16. enum    {    GAD_CALLING=1,GAD_TIME,GAD_NOTE,
  17.             GAD_SKIP,GAD_REMOVE,GAD_ONLINE,GAD_ABORT
  18.         };
  19.  
  20. STATIC VOID __stdargs
  21. PrintBox(struct LayoutHandle *Handle,LONG Box,LONG Line,STRPTR String,...)
  22. {
  23.     UBYTE     LocalBuffer[256];
  24.     va_list     VarArgs;
  25.  
  26.     va_start(VarArgs,String);
  27.     VSPrintf(LocalBuffer,String,VarArgs);
  28.     va_end(VarArgs);
  29.  
  30.     LT_SetAttributes(Handle,Box,
  31.         LABX_Index,    Line,
  32.         LABX_Text,    LocalBuffer,
  33.     TAG_DONE);
  34. }
  35.  
  36.     /* BuildName(STRPTR Name):
  37.      *
  38.      *    Build a file name from a BBS name and the current date.
  39.      */
  40.  
  41. STATIC VOID __regargs
  42. BuildName(STRPTR Name,STRPTR Date)
  43. {
  44.     if(Date[0])
  45.     {
  46.         WORD    NameLen = strlen(Name),
  47.                 DateLen = strlen(Date),
  48.                 Delta;
  49.  
  50.         if((Delta = NameLen + 1 + DateLen - 32) > 0)
  51.             Name[NameLen - Delta] = 0;
  52.  
  53.         strcat(Name,"_");
  54.         strcat(Name,Date);
  55.     }
  56. }
  57.  
  58.     /* OpenAutoCaptureFile(STRPTR SomeName):
  59.      *
  60.      *    Open a capture file.
  61.      */
  62.  
  63. STATIC VOID __regargs
  64. OpenAutoCaptureFile(STRPTR SomeName)
  65. {
  66.     UBYTE            SharedBuffer[MAX_FILENAME_LENGTH],
  67.                     Name[50],
  68.                     Date[20],
  69.                     Time[20];
  70.     struct DateTime    DateTime;
  71.  
  72.         /* Get the current time and date. */
  73.  
  74.     DateStamp(&DateTime . dat_Stamp);
  75.  
  76.         /* Prepare for date conversion. */
  77.  
  78.     DateTime . dat_Format    = FORMAT_DOS;
  79.     DateTime . dat_Flags    = 0;
  80.     DateTime . dat_StrDay    = NULL;
  81.     DateTime . dat_StrDate    = Date;
  82.     DateTime . dat_StrTime    = Time;
  83.  
  84.         /* Convert the date. */
  85.  
  86.     if(DateToStr(&DateTime))
  87.     {
  88.             /* Remember the BBS name. */
  89.  
  90.         strcpy(Name,SomeName);
  91.  
  92.             /* Append the creation date if necessary. */
  93.  
  94.         if(Config -> CaptureConfig -> AutoCaptureDate == AUTOCAPTURE_DATE_NAME)
  95.             BuildName(Name,Date);
  96.  
  97.             /* Make it a reasonable name. */
  98.  
  99.         FixName(Name);
  100.  
  101.             /* Get the capture file path. */
  102.  
  103.         strcpy(SharedBuffer,Config -> CaptureConfig -> CapturePath);
  104.  
  105.             /* Try to build a valid file and path name. */
  106.  
  107.         if(AddPart(SharedBuffer,Name,MAX_FILENAME_LENGTH))
  108.         {
  109.                 /* Is the capture file still open? */
  110.  
  111.             if(FileCapture)
  112.             {
  113.                     /* Close the file. */
  114.  
  115.                 BufferClose(FileCapture);
  116.  
  117.                 FileCapture = NULL;
  118.  
  119.                     /* Any data written? */
  120.  
  121.                 if(!GetFileSize(CaptureName))
  122.                     DeleteFile(CaptureName);
  123.                 else
  124.                 {
  125.                     AddProtection(CaptureName,FIBF_EXECUTE);
  126.  
  127.                     if(Config -> MiscConfig -> CreateIcons)
  128.                         AddIcon(CaptureName,FILETYPE_TEXT,TRUE);
  129.                 }
  130.             }
  131.  
  132.                 /* Try to append the new data. */
  133.  
  134.             if(FileCapture = BufferOpen(SharedBuffer,"a"))
  135.             {
  136.                     /* Set the menu checkmark. */
  137.  
  138.                 CheckItem(MEN_CAPTURE_TO_FILE,TRUE);
  139.  
  140.                     /* Remember the current capture file name. */
  141.  
  142.                 strcpy(CaptureName,SharedBuffer);
  143.  
  144.                     /* Add the creation date if necessary. */
  145.  
  146.                 if(Config -> CaptureConfig -> AutoCaptureDate == AUTOCAPTURE_DATE_INCLUDE)
  147.                 {
  148.                     UBYTE DateTimeBuffer[256];
  149.  
  150.                     if(FormatStamp(&DateTime . dat_Stamp,NULL,NULL,DateTimeBuffer,FALSE))
  151.                         BPrintf(FileCapture,LocaleString(MSG_DIALPANEL_FILE_CREATED_TXT),DateTimeBuffer);
  152.                 }
  153.             }
  154.             else
  155.                 CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  156.  
  157.             ConOutputUpdate();
  158.         }
  159.     }
  160. }
  161.  
  162.     /* Connect(struct PhoneNode *DialNode,STRPTR NumberBuffer):
  163.      *
  164.      *    Perform connect action(s).
  165.      */
  166.  
  167. STATIC VOID __regargs
  168. Connect(struct PhoneNode *DialNode,STRPTR NumberBuffer)
  169. {
  170.     if(DialNode -> Entry)
  171.     {
  172.         UpdateConfig(DialNode -> Entry -> Config,Config);
  173.  
  174.         ConfigChanged = FALSE;
  175.  
  176.         MakeCall(DialNode -> Entry -> Header -> Name,NumberBuffer);
  177.  
  178.         ObtainSemaphore(&PatternSemaphore);
  179.  
  180.         ChosenPattern = FindTimeDate(PatternList,NumberBuffer);
  181.  
  182.         SelectTime(DialNode -> Entry,ChosenPattern,NULL);
  183.  
  184.         ChosenEntry    = DialNode -> Entry;
  185.         WhichUnit    = DT_FIRST_UNIT;
  186.         CurrentPay    = 0;
  187.         SendStartup    = TRUE;
  188.  
  189.         ReleaseSemaphore(&PatternSemaphore);
  190.  
  191.         strcpy(Password,DialNode -> Entry -> Header -> Password);
  192.         strcpy(UserName,DialNode -> Entry -> Header -> UserName);
  193.  
  194.         strcpy(CurrentBBSName,DialNode -> Entry -> Header -> Name);
  195.         strcpy(CurrentBBSComment,DialNode -> Entry -> Header -> Comment);
  196.  
  197.         strcpy(CurrentBBSNumber,NumberBuffer);
  198.  
  199.         if(DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  200.         {
  201.             OnlinePlus = DialNode -> Entry -> Config -> ModemConfig -> TimeToConnect;
  202.  
  203.             if(DialNode -> Entry -> Config -> ModemConfig -> ConnectLimit > 0 && DialNode -> Entry -> Config -> ModemConfig -> ConnectLimitMacro[0])
  204.             {
  205.                 LimitCount = DialNode -> Entry -> Config -> ModemConfig -> ConnectLimit;
  206.  
  207.                 strcpy(LimitMacro,DialNode -> Entry -> Config -> ModemConfig -> ConnectLimitMacro);
  208.             }
  209.             else
  210.                 LimitCount = -1;
  211.         }
  212.         else
  213.         {
  214.             OnlinePlus = Config -> ModemConfig -> TimeToConnect;
  215.  
  216.             if(Config -> ModemConfig -> ConnectLimit > 0 && Config -> ModemConfig -> ConnectLimitMacro[0])
  217.             {
  218.                 LimitCount = Config -> ModemConfig -> ConnectLimit;
  219.  
  220.                 strcpy(LimitMacro,Config -> ModemConfig -> ConnectLimitMacro);
  221.             }
  222.             else
  223.                 LimitCount = -1;
  224.         }
  225.  
  226.         LogAction(LocaleString(MSG_DIALPANEL_CONNECTED_TO_1_TXT),DialNode -> Entry -> Header -> Name,NumberBuffer);
  227.     }
  228.     else
  229.     {
  230.         OnlinePlus = Config -> ModemConfig -> TimeToConnect;
  231.  
  232.         MakeCall("???",NumberBuffer);
  233.  
  234.         ObtainSemaphore(&PatternSemaphore);
  235.  
  236.         ChosenPattern = FindTimeDate(PatternList,NumberBuffer);
  237.  
  238.         SelectTime(NULL,ChosenPattern,NULL);
  239.  
  240.         ChosenEntry    = NULL;
  241.  
  242.         ReleaseSemaphore(&PatternSemaphore);
  243.  
  244.         CurrentPay    = 0;
  245.         Password[0]    = 0;
  246.         UserName[0]    = 0;
  247.         SendStartup    = FALSE;
  248.  
  249.         CurrentBBSName[0]    = 0;
  250.         CurrentBBSComment[0]    = 0;
  251.  
  252.         strcpy(CurrentBBSNumber,NumberBuffer);
  253.  
  254.         if(Config -> ModemConfig -> ConnectLimit > 0 && Config -> ModemConfig -> ConnectLimitMacro[0])
  255.         {
  256.             LimitCount = Config -> ModemConfig -> ConnectLimit;
  257.  
  258.             strcpy(LimitMacro,Config -> ModemConfig -> ConnectLimitMacro);
  259.         }
  260.         else
  261.             LimitCount = -1;
  262.  
  263.         LogAction(LocaleString(MSG_DIALPANEL_CONNECTED_TO_2_TXT),NumberBuffer);
  264.     }
  265.  
  266.         /* We are now online. */
  267.  
  268.     ObtainSemaphore(&OnlineSemaphore);
  269.  
  270.     Online = TRUE;
  271.  
  272.     ReleaseSemaphore(&OnlineSemaphore);
  273.  
  274.         /* Open auto-capture file. */
  275.  
  276.     if(Config -> CaptureConfig -> ConnectAutoCapture && Config -> CaptureConfig -> CapturePath[0])
  277.     {
  278.         if(DialNode -> Entry)
  279.             OpenAutoCaptureFile(DialNode -> Entry -> Header -> Name);
  280.         else
  281.             OpenAutoCaptureFile(LocaleString(MSG_DIALPANEL_CAPTURE_NAME_TXT));
  282.     }
  283.  
  284.         /* Remove node from
  285.          * dialing list and
  286.          * perform system
  287.          * setup.
  288.          */
  289.  
  290.     if(DialNode -> Entry)
  291.         RemoveDialNode(DialNode);
  292.  
  293.     Remove(&DialNode -> VanillaNode);
  294.  
  295.     FreeVecPooled(DialNode);
  296.  
  297.     if(PrivateConfig -> MiscConfig -> BackupConfig)
  298.     {
  299.         if(!BackupConfig)
  300.         {
  301.             if(BackupConfig = CreateConfiguration(TRUE))
  302.                 SaveConfig(PrivateConfig,BackupConfig);
  303.         }
  304.     }
  305.  
  306.         /* Make sure that the following
  307.          * setup/initialization will not
  308.          * touch the serial configuration.
  309.          */
  310.  
  311.     memcpy(PrivateConfig -> SerialConfig,Config -> SerialConfig,sizeof(struct SerialSettings));
  312.  
  313.     ConfigSetup();
  314.  
  315.         /* Reset the scanner. */
  316.  
  317.     FlowInit(TRUE);
  318. }
  319.  
  320.     /* OpenDialPanel(BOOL *Record):
  321.      *
  322.      *    Open the dialing panel.
  323.      */
  324.  
  325. STATIC LayoutHandle * __regargs
  326. OpenDialPanel(BOOL *Record)
  327. {
  328.     LayoutHandle *Handle;
  329.  
  330.     if(Handle = LT_CreateHandleTags(Window -> WScreen,
  331.         LH_LocaleHook,    &LocaleHook,
  332.     TAG_DONE))
  333.     {
  334.         LT_New(Handle,
  335.             LA_Type,    VERTICAL_KIND,
  336.         TAG_DONE);
  337.         {
  338.             LT_New(Handle,
  339.                 LA_Type,    VERTICAL_KIND,
  340.             TAG_DONE);
  341.             {
  342.                 LT_New(Handle,
  343.                     LA_Type,    VERTICAL_KIND,
  344.                 TAG_DONE);
  345.                 {
  346.                     LT_New(Handle,
  347.                         LA_Type,            BOX_KIND,
  348.                         LA_ID,                GAD_CALLING,
  349.                         LA_Chars,            45,
  350.                         LA_Lines,            4,
  351.                         LABX_ReserveSpace,    TRUE,
  352.                         LABX_FirstLabel,    MSG_DIALPANEL_CALLING_TXT,
  353.                         LABX_LastLabel,        MSG_DIALPANEL_NEXT_TXT,
  354.                     TAG_DONE);
  355.  
  356.                     LT_New(Handle,
  357.                         LA_Type,            BOX_KIND,
  358.                         LA_ID,                GAD_TIME,
  359.                         LA_Chars,            45,
  360.                         LA_Lines,            2,
  361.                         LABX_ReserveSpace,    TRUE,
  362.                         LABX_FirstLabel,    MSG_DIALPANEL_TIMEOUT_TXT,
  363.                         LABX_LastLabel,        MSG_DIALPANEL_ATTEMPT_TXT,
  364.                     TAG_DONE);
  365.  
  366.                     LT_New(Handle,
  367.                         LA_Type,            BOX_KIND,
  368.                         LA_ID,                GAD_NOTE,
  369.                         LA_Chars,            45,
  370.                         LA_Lines,            1,
  371.                         LABX_ReserveSpace,    TRUE,
  372.                         LABX_FirstLabel,    MSG_DIALPANEL_MESSAGE_TXT,
  373.                         LABX_LastLabel,        MSG_DIALPANEL_MESSAGE_TXT,
  374.                     TAG_DONE);
  375.  
  376.                     LT_EndGroup(Handle);
  377.                 }
  378.  
  379.                 LT_New(Handle,
  380.                     LA_Type,    VERTICAL_KIND,
  381.                 TAG_DONE);
  382.                 {
  383.                     LT_New(Handle,
  384.                         LA_Type,        XBAR_KIND,
  385.                     TAG_DONE);
  386.  
  387.                     LT_New(Handle,
  388.                         LA_Type,        CHECKBOX_KIND,
  389.                         LA_LabelID,        MSG_DIALPANEL_RECORD_ON_CONNECTION_TXT,
  390.                         LA_BOOL,        Record,
  391.                     TAG_DONE);
  392.  
  393.                     LT_EndGroup(Handle);
  394.                 }
  395.  
  396.                 LT_EndGroup(Handle);
  397.             }
  398.  
  399.             LT_New(Handle,
  400.                 LA_Type,VERTICAL_KIND,
  401.             TAG_DONE);
  402.             {
  403.                 LT_New(Handle,
  404.                     LA_Type,        XBAR_KIND,
  405.                     LAXB_FullSize,    TRUE,
  406.                 TAG_DONE);
  407.  
  408.                 LT_EndGroup(Handle);
  409.             }
  410.  
  411.             LT_New(Handle,LA_Type,HORIZONTAL_KIND,
  412.                 LAGR_Spread,    TRUE,
  413.             TAG_DONE);
  414.             {
  415.                 LT_New(Handle,
  416.                     LA_Type,        BUTTON_KIND,
  417.                     LA_LabelID,        MSG_DIALPANEL_SKIP_GAD,
  418.                     LA_ID,            GAD_SKIP,
  419.                     LABT_ExtraFat,    TRUE,
  420.                     GA_Disabled,    TRUE,
  421.                 TAG_DONE);
  422.  
  423.                 LT_New(Handle,
  424.                     LA_Type,        BUTTON_KIND,
  425.                     LA_LabelID,        MSG_GLOBAL_REMOVE_GAD,
  426.                     LA_ID,            GAD_REMOVE,
  427.                     LABT_ExtraFat,    TRUE,
  428.                     GA_Disabled,    TRUE,
  429.                 TAG_DONE);
  430.  
  431.                 LT_New(Handle,
  432.                     LA_Type,        BUTTON_KIND,
  433.                     LA_LabelID,        MSG_DIALPANEL_GO_TO_ONLINE_GAD,
  434.                     LA_ID,            GAD_ONLINE,
  435.                     LABT_ReturnKey,    TRUE,
  436.                     LABT_ExtraFat,    TRUE,
  437.                 TAG_DONE);
  438.  
  439.                 LT_New(Handle,
  440.                     LA_Type,        BUTTON_KIND,
  441.                     LA_LabelID,        MSG_GLOBAL_ABORT_GAD,
  442.                     LA_ID,            GAD_ABORT,
  443.                     LABT_ExtraFat,    TRUE,
  444.                 TAG_DONE);
  445.  
  446.                 LT_EndGroup(Handle);
  447.             }
  448.  
  449.             LT_EndGroup(Handle);
  450.         }
  451.  
  452.         if(LT_Build(Handle,
  453.             LAWN_TitleID,        MSG_DIALPANEL_DIALING_TXT,
  454.             LAWN_IDCMP,            IDCMP_CLOSEWINDOW,
  455.             LAWN_HelpHook,        &GuideHook,
  456.             LAWN_Parent,        Window,
  457.             WA_DepthGadget,        TRUE,
  458.             WA_CloseGadget,        TRUE,
  459.             WA_DragBar,            TRUE,
  460.             WA_RMBTrap,            TRUE,
  461.             WA_Activate,        TRUE,
  462.         TAG_DONE))
  463.             return(Handle);
  464.         else
  465.             LT_DeleteHandle(Handle);
  466.     }
  467.  
  468.     return(NULL);
  469. }
  470.  
  471.     /* DialPanel():
  472.      *
  473.      *    This routine opens a small window in the middle of the
  474.      *    console window and walks down the list of numbers to
  475.      *    dial.
  476.      */
  477.  
  478. BOOL
  479. DialPanel()
  480. {
  481.     LayoutHandle    *Handle;
  482.     BOOL             Result = FALSE,
  483.                      Record = FALSE;
  484.  
  485.     BlockWindows();
  486.  
  487.     if(Handle = OpenDialPanel(&Record))
  488.     {
  489.         STATIC struct SerialSettings OriginalSerialConfig;
  490.  
  491.         struct Window        *PanelWindow = Handle -> Window;
  492.  
  493.         UBYTE                 ExitCommand[80],
  494.                              ExitBuffer[80],
  495.                               InitBuffer[80],
  496.                               PrefixBuffer[80],
  497.                               NumberBuffer[100];
  498.  
  499.         UBYTE                 DialBuffer[300];
  500.  
  501.         STRPTR                 NextExit,
  502.                              NextInit,
  503.                              NextPrefix,
  504.                              NextNumber;
  505.  
  506.         WORD                 NumberCount,
  507.                              NumberCurrent;
  508.  
  509.         LONG                 DialTimeout,
  510.                              DialRetries    = 0,
  511.                              DialAttempt    = 0;
  512.         struct PhoneNode    *DialNode        = NULL;
  513.  
  514.         LONG                 RedialTimeout;
  515.  
  516.         STRPTR                 CallingName;
  517.         UBYTE                 CallingBuffer[80];
  518.  
  519.         BOOL                 Dialing    = FALSE,
  520.                              Calling    = FALSE,
  521.                              Waiting    = FALSE,
  522.                              Skipping    = FALSE,
  523.                              Aborting    = FALSE,
  524.                              Error        = FALSE,
  525.                              Done        = FALSE,
  526.                              NeedHangUp    = TRUE;
  527.  
  528.         WORD                 RunCount    = 0;
  529.  
  530.             /* Reset the area code scanner data. */
  531.  
  532.         ObtainSemaphore(&PatternSemaphore);
  533.  
  534.         ChosenEntry        = NULL;
  535.         ChosenPattern    = NULL;
  536.  
  537.         ReleaseSemaphore(&PatternSemaphore);
  538.  
  539.             /* We are now dialing. */
  540.  
  541.         Status = STATUS_DIALING;
  542.  
  543.             /* Remember the original serial settings, so we
  544.              * can return to them later.
  545.              */
  546.  
  547.         CopyMem(Config -> SerialConfig,&OriginalSerialConfig,sizeof(struct SerialSettings));
  548.  
  549.             /* Set up the AmigaGuide help context. */
  550.  
  551.         GuideContext(CONTEXT_DIAL);
  552.  
  553.             /* No exit command is defined yet. */
  554.  
  555.         ExitCommand[0] = 0;
  556.  
  557.             /* Make the current one the active one. */
  558.  
  559.         LT_ShowWindow(Handle,TRUE);
  560.  
  561.         PushWindow(PanelWindow);
  562.  
  563.             /* Make a backup of the current configuration. */
  564.  
  565.         SaveConfig(Config,PrivateConfig);
  566.  
  567.             /* Don't echo serial output unless requested by the user. */
  568.  
  569.         if(!Config -> ModemConfig -> VerboseDialing)
  570.             Quiet = TRUE;
  571.  
  572.             /* Perform full sequence check. */
  573.  
  574.         FullCheck = TRUE;
  575.  
  576.             /* Reset the scanner. */
  577.  
  578.         FlowInit(TRUE);
  579.  
  580.             /* Clear the signals. */
  581.  
  582.         SetSignal(0,SIG_SKIP | SIG_BREAK);
  583.  
  584.             /* The big dialing loop. */
  585.  
  586.         do
  587.         {
  588.                 /* Any window input? */
  589.  
  590.             if(SetSignal(0,PORTMASK(PanelWindow -> UserPort)) & PORTMASK(PanelWindow -> UserPort))
  591.             {
  592.                 struct IntuiMessage    *Msg;
  593.                 ULONG                 MsgClass,
  594.                                      MsgQualifier;
  595.                 UWORD                 MsgCode;
  596.                 struct Gadget        *MsgGadget;
  597.  
  598.                 while(Msg = LT_GetIMsg(Handle))
  599.                 {
  600.                     MsgClass        = Msg -> Class;
  601.                     MsgCode            = Msg -> Code;
  602.                     MsgQualifier    = Msg -> Qualifier;
  603.                     MsgGadget        = Msg -> IAddress;
  604.  
  605.                     LT_ReplyIMsg(Msg);
  606.  
  607.                         /* Convert the space keypress into a
  608.                          * skip command.
  609.                          */
  610.  
  611.                     if(MsgClass == IDCMP_RAWKEY)
  612.                     {
  613.                         if((Dialing || Waiting) && LT_GetCode(MsgQualifier,MsgClass,MsgCode,MsgGadget) == ' ')
  614.                         {
  615.                             LT_PressButton(Handle,GAD_SKIP);
  616.  
  617.                             Skipping = TRUE;
  618.                         }
  619.                     }
  620.  
  621.                         /* Close the window, hang up the line,
  622.                          * return to the phone book.
  623.                          */
  624.  
  625.                     if(MsgClass == IDCMP_CLOSEWINDOW)
  626.                         Aborting = Done = Result = TRUE;
  627.  
  628.                         /* So a button was pressed. */
  629.  
  630.                     if(MsgClass == IDCMP_GADGETUP)
  631.                     {
  632.                         switch(MsgGadget -> GadgetID)
  633.                         {
  634.                                 /* Remove the currently active dialing
  635.                                  * list entry.
  636.                                  */
  637.  
  638.                             case GAD_REMOVE:
  639.  
  640.                                     /* This makes sense only while
  641.                                      * we are dialing.
  642.                                      */
  643.  
  644.                                 if(Dialing)
  645.                                 {
  646.                                     struct PhoneNode    *NextNode = NULL;
  647.                                     BOOL                 UseHangUp;
  648.  
  649.                                         /* If still dialing, hang up first. */
  650.  
  651.                                     if(DialNode -> Entry && DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  652.                                         UseHangUp = DialNode -> Entry -> Config -> ModemConfig -> AbortHangsUp;
  653.                                     else
  654.                                         UseHangUp = Config -> ModemConfig -> AbortHangsUp;
  655.  
  656.                                     if(UseHangUp)
  657.                                         HangUp();
  658.                                     else
  659.                                     {
  660.                                         SerWrite("\r",1);
  661.  
  662.                                         WaitTime(1,0);
  663.                                     }
  664.  
  665.                                         /* Ignore the response of the modem. */
  666.  
  667.                                     HandleSerial();
  668.  
  669.                                     FlowInit(TRUE);
  670.  
  671.                                         /* Is there another entry in the list? */
  672.  
  673.                                     if(DialNode -> VanillaNode . ln_Succ -> ln_Succ)
  674.                                         NextNode = (struct PhoneNode *)DialNode -> VanillaNode . ln_Succ;
  675.                                     else
  676.                                     {
  677.                                             /* No, there isn't; do we have a list with
  678.                                              * at least two entries in it?
  679.                                              */
  680.  
  681.                                         if(DialList -> lh_Head -> ln_Succ -> ln_Succ)
  682.                                         {
  683.                                                 /* Yet another dialing attempt coming up... */
  684.  
  685.                                             DialAttempt++;
  686.  
  687.                                                 /* Check for dial retry limit. */
  688.  
  689.                                             if(DialRetries >= 0 && DialAttempt >= DialRetries)
  690.                                             {
  691.                                                 PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  692.  
  693.                                                 WakeUp(PanelWindow,SOUND_BELL);
  694.  
  695.                                                 WaitTime(2,0);
  696.  
  697.                                                 Say(LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  698.  
  699.                                                 Done = TRUE;
  700.                                             }
  701.                                             else
  702.                                             {
  703.                                                     /* Grab first list entry and continue. */
  704.  
  705.                                                 NextNode = (struct PhoneNode *)DialList -> lh_Head;
  706.                                             }
  707.                                         }
  708.                                         else
  709.                                         {
  710.                                                 /* That's all, folks! */
  711.  
  712.                                             PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_DIALING_LIST_IS_EMPTY_TXT));
  713.  
  714.                                             WaitTime(2,0);
  715.  
  716.                                             Done = TRUE;
  717.                                         }
  718.                                     }
  719.  
  720.                                         /* Remove dial entry from list. */
  721.  
  722.                                     if(DialNode -> Entry)
  723.                                         RemoveDialNode(DialNode);
  724.  
  725.                                     Remove(&DialNode -> VanillaNode);
  726.  
  727.                                     FreeVecPooled(DialNode);
  728.  
  729.                                         /* Is there an entry to proceed with? */
  730.  
  731.                                     if(DialNode = NextNode)
  732.                                     {
  733.                                         NextNumber = NULL;
  734.  
  735.                                         Calling = TRUE;
  736.                                     }
  737.                                 }
  738.  
  739.                                 break;
  740.  
  741.                             case GAD_SKIP:
  742.  
  743.                                 if(Dialing || Waiting)
  744.                                     Skipping = TRUE;
  745.  
  746.                                 break;
  747.  
  748.                             case GAD_ONLINE:
  749.  
  750.                                     /* Go online so soon? */
  751.  
  752.                                 if(!DialNode)
  753.                                 {
  754.                                     DialNode = (struct PhoneNode *)DialList -> lh_Head;
  755.  
  756.                                     if(DialNode -> Entry)
  757.                                         ExtractString(DialNode -> Entry -> Header -> Number,NumberBuffer,TRUE);
  758.                                     else
  759.                                         ExtractString(DialNode -> VanillaNode . ln_Name,NumberBuffer,TRUE);
  760.                                 }
  761.  
  762.                                 Connect(DialNode,NumberBuffer);
  763.  
  764.                                 Done = TRUE;
  765.  
  766.                                 break;
  767.  
  768.                                 /* Abort the dialing process. */
  769.  
  770.                             case GAD_ABORT:
  771.  
  772.                                 Aborting = Done = TRUE;
  773.  
  774.                                 break;
  775.                         }
  776.                     }
  777.  
  778.                     if(Done)
  779.                         break;
  780.                 }
  781.             }
  782.  
  783.                 /* Abort the process? */
  784.  
  785.             if(SetSignal(0,SIG_BREAK) & SIG_BREAK)
  786.             {
  787.                 if(!Done)
  788.                     Aborting = Done = TRUE;
  789.             }
  790.  
  791.                 /* Skip the current action? */
  792.  
  793.             if(SetSignal(0,SIG_SKIP) & SIG_SKIP)
  794.             {
  795.                 if((Dialing || Waiting) && !Done)
  796.                     Skipping = TRUE;
  797.             }
  798.  
  799.                 /* Are we to abort? */
  800.  
  801.             if(Aborting)
  802.             {
  803.                     /* Hang up if necessary. */
  804.  
  805.                 if(Dialing)
  806.                 {
  807.                     BOOL UseHangUp;
  808.  
  809.                     PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ABORTING_TXT));
  810.  
  811.                     if(DialNode -> Entry && DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  812.                         UseHangUp = DialNode -> Entry -> Config -> ModemConfig -> AbortHangsUp;
  813.                     else
  814.                         UseHangUp = Config -> ModemConfig -> AbortHangsUp;
  815.  
  816.                     if(UseHangUp)
  817.                         HangUp();
  818.                     else
  819.                     {
  820.                         SerWrite("\r",1);
  821.                         WaitTime(1,0);
  822.                     }
  823.  
  824.                         /* Ignore the response of the modem. */
  825.  
  826.                     HandleSerial();
  827.  
  828.                     FlowInit(TRUE);
  829.                 }
  830.             }
  831.  
  832.                 /* Start at the beginning. */
  833.  
  834.             if(!DialNode && !Done)
  835.             {
  836.                 DialNode = (struct PhoneNode *)DialList -> lh_Head;
  837.  
  838.                 LT_SetAttributes(Handle,GAD_SKIP,
  839.                     GA_Disabled,    FALSE,
  840.                 TAG_DONE);
  841.  
  842.                 LT_SetAttributes(Handle,GAD_REMOVE,
  843.                     GA_Disabled,    FALSE,
  844.                 TAG_DONE);
  845.  
  846.                 Calling = TRUE;
  847.  
  848.                 NextNumber = NULL;
  849.             }
  850.  
  851.                 /* Are we to start a call? */
  852.  
  853.             if(Calling && !Done)
  854.             {
  855.                     /* Reset the sequence scanner, the user may have skipped
  856.                      * the previous dial attempt causing the modem to return
  857.                      * `NO CARRIER'. To prevent the dialer from skipping the
  858.                      * next dial entry as well as the previous we have to
  859.                      * flush any data pending on the serial line.
  860.                      */
  861.  
  862.                 FlowInit(TRUE);
  863.  
  864.                     /* Is this the first number for this dial entry? */
  865.  
  866.                 if(!NextNumber)
  867.                 {
  868.                     STRPTR    PhoneNumber;
  869.                     WORD    i,Len;
  870.  
  871.                         /* Does this entry have a configuration attached? */
  872.  
  873.                     if(DialNode -> Entry)
  874.                     {
  875.                             /* Get the phone number. */
  876.  
  877.                         PhoneNumber = DialNode -> Entry -> Header -> Number;
  878.  
  879.                             /* Pick up the modem configuration. */
  880.  
  881.                         if(DialNode -> Entry -> Config -> ModemConfig)
  882.                         {
  883.                             NextInit    = ExtractString(DialNode -> Entry -> Config -> ModemConfig -> ModemInit,    InitBuffer,        FALSE);
  884.                             NextExit    = ExtractString(DialNode -> Entry -> Config -> ModemConfig -> ModemExit,    ExitBuffer,        FALSE);
  885.                             NextPrefix    = ExtractString(DialNode -> Entry -> Config -> ModemConfig -> DialPrefix,    PrefixBuffer,    FALSE);
  886.                         }
  887.                         else
  888.                         {
  889.                             NextInit    = ExtractString(Config -> ModemConfig -> ModemInit,        InitBuffer,        FALSE);
  890.                             NextExit    = ExtractString(Config -> ModemConfig -> ModemExit,        ExitBuffer,        FALSE);
  891.                             NextPrefix    = ExtractString(Config -> ModemConfig -> DialPrefix,    PrefixBuffer,    FALSE);
  892.                         }
  893.                     }
  894.                     else
  895.                     {
  896.                             /* Get the phone number. */
  897.  
  898.                         PhoneNumber = DialNode -> VanillaNode . ln_Name;
  899.  
  900.                             /* Pick up the modem configuration. */
  901.  
  902.                         NextInit    = ExtractString(Config -> ModemConfig -> ModemInit,        InitBuffer,        FALSE);
  903.                         NextExit    = ExtractString(Config -> ModemConfig -> ModemExit,        ExitBuffer,        FALSE);
  904.                         NextPrefix    = ExtractString(Config -> ModemConfig -> DialPrefix,    PrefixBuffer,    FALSE);
  905.                     }
  906.  
  907.                             /* Extract the phone number. */
  908.  
  909.                     NextNumber = ExtractString(PhoneNumber,NumberBuffer,TRUE);
  910.  
  911.                         /* Count the number of phone numbers separated
  912.                          * by "|" characters.
  913.                          */
  914.  
  915.                     Len = strlen(PhoneNumber);
  916.  
  917.                     for(i = 0, NumberCount = 0 ; i < Len ; i++)
  918.                     {
  919.                         if(PhoneNumber[i] == '|')
  920.                         {
  921.                             WORD j;
  922.  
  923.                             for(j = i + 1 ; j <= Len ; j++)
  924.                             {
  925.                                 if(PhoneNumber[j] != ' ' && PhoneNumber[j] != 0)
  926.                                 {
  927.                                     if(PhoneNumber[j] != '|')
  928.                                         NumberCount++;
  929.  
  930.                                     break;
  931.                                 }
  932.                             }
  933.                         }
  934.                     }
  935.  
  936.                         /* This is the first one. */
  937.  
  938.                     NumberCurrent = 0;
  939.                 }
  940.                 else
  941.                 {
  942.                         /* Now for multiple phone numbers separated
  943.                          * by `|' characters. If `NextNumber' happens
  944.                          * to be zero, we will prepare to extract
  945.                          * the first phone number from the list.
  946.                          * In any other case we will try to obtain
  947.                          * the next number.
  948.                          */
  949.  
  950.                     NextNumber    = ExtractString(NextNumber,    NumberBuffer,    TRUE);
  951.                     NextInit    = ExtractString(NextInit,    InitBuffer,        FALSE);
  952.                     NextExit    = ExtractString(NextExit,    ExitBuffer,        FALSE);
  953.                     NextPrefix    = ExtractString(NextPrefix,    PrefixBuffer,    FALSE);
  954.  
  955.                     NumberCurrent++;
  956.                 }
  957.  
  958.                     /* Send the modem exit string before we
  959.                      * will need to reconfigure the serial
  960.                      * device driver.
  961.                      */
  962.  
  963.                 if(ExitCommand[0])
  964.                 {
  965.                     PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_SENDING_MODEM_EXIT_COMMAND_TXT));
  966.  
  967.                     FlowInit(TRUE);
  968.  
  969.                     SerialCommand(ExitCommand);
  970.  
  971.                     WaitTime(1,0);
  972.  
  973.                     HandleSerial();
  974.  
  975.                     if(FlowInfo . Changed && FlowInfo . Error)
  976.                     {
  977.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  978.  
  979.                         WakeUp(PanelWindow,SOUND_ERROR);
  980.  
  981.                         Error = Done = TRUE;
  982.                     }
  983.                 }
  984.  
  985.                     /* We will need to change the serial parameters
  986.                      * in order to establish a connection.
  987.                      */
  988.  
  989.                 if(!Done)
  990.                 {
  991.                     if(DialNode -> Entry && DialNode -> Entry -> Config -> SerialConfig)
  992.                     {
  993.                         if(ReconfigureSerial(PanelWindow,DialNode -> Entry -> Config -> SerialConfig) == RECONFIGURE_FAILURE)
  994.                         {
  995.                             WakeUp(PanelWindow,SOUND_ERROR);
  996.  
  997.                             Error = Done = TRUE;
  998.                         }
  999.                     }
  1000.                     else
  1001.                     {
  1002.                         if(ReconfigureSerial(PanelWindow,&OriginalSerialConfig) == RECONFIGURE_FAILURE)
  1003.                         {
  1004.                             WakeUp(PanelWindow,SOUND_ERROR);
  1005.  
  1006.                             Error = Done = TRUE;
  1007.                         }
  1008.                     }
  1009.                 }
  1010.  
  1011.                     /* Send the modem init command. */
  1012.  
  1013.                 if(InitBuffer[0] && !Done)
  1014.                 {
  1015.                     PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_SENDING_MODEM_INIT_COMMAND_TXT));
  1016.  
  1017.                     FlowInit(TRUE);
  1018.  
  1019.                     SerialCommand(InitBuffer);
  1020.  
  1021.                     WaitTime(1,0);
  1022.  
  1023.                     HandleSerial();
  1024.  
  1025.                     if(FlowInfo . Changed && FlowInfo . Error)
  1026.                     {
  1027.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  1028.  
  1029.                         WakeUp(PanelWindow,SOUND_ERROR);
  1030.  
  1031.                         Error = Done = TRUE;
  1032.                     }
  1033.                 }
  1034.  
  1035.                 if(!Done)
  1036.                 {
  1037.                         /* Remember the new exit command. */
  1038.  
  1039.                     strcpy(ExitCommand,ExitBuffer);
  1040.  
  1041.                     if(DialNode -> Entry)
  1042.                         CallingName = DialNode -> Entry -> Header -> Name;
  1043.                     else
  1044.                         CallingName = LocaleString(MSG_GLOBAL_UNKNOWN_TXT);
  1045.  
  1046.                         /* If there is more than one number to follow, say so. */
  1047.  
  1048.                     if(NumberCount)
  1049.                     {
  1050.                         UBYTE LocalBuffer[40];
  1051.  
  1052.                         SPrintf(LocalBuffer,LocaleString(MSG_DIALPANEL_ATTEMPT_OF_TXT),NumberCurrent + 1,NumberCount + 1);
  1053.  
  1054.                         SPrintf(CallingBuffer,"%s (%s)",CallingName,LocalBuffer);
  1055.  
  1056.                         CallingName = CallingBuffer;
  1057.                     }
  1058.  
  1059.                     PrintBox(Handle,GAD_CALLING,0,CallingName);
  1060.  
  1061.                         /* Show the comment if any. */
  1062.  
  1063.                     if(DialNode -> Entry && DialNode -> Entry -> Header -> Comment[0])
  1064.                         PrintBox(Handle,GAD_CALLING,1,DialNode -> Entry -> Header -> Comment);
  1065.                     else
  1066.                         PrintBox(Handle,GAD_CALLING,1,"-");
  1067.  
  1068.                         /* Display the number being called. */
  1069.  
  1070.                     if(DialNode -> Entry)
  1071.                         Say(LocaleString(MSG_DIALPANEL_NOW_CALLING_TXT),DialNode -> Entry -> Header -> Name);
  1072.                     else
  1073.                         Say(LocaleString(MSG_DIALPANEL_NOW_CALLING_TXT),NumberBuffer);
  1074.  
  1075.                     PrintBox(Handle,GAD_CALLING,2,NumberBuffer);
  1076.  
  1077.                         /* Display the name of the service to call next. */
  1078.  
  1079.                     if(NextNumber)
  1080.                     {
  1081.                         if(DialNode -> Entry)
  1082.                             CallingName = DialNode -> Entry -> Header -> Name;
  1083.                         else
  1084.                             CallingName = DialNode -> VanillaNode . ln_Name;
  1085.                     }
  1086.                     else
  1087.                     {
  1088.                         if(DialNode -> VanillaNode . ln_Succ -> ln_Succ)
  1089.                         {
  1090.                             if(DialNode -> Entry)
  1091.                                 CallingName = ((struct PhoneNode *)DialNode -> VanillaNode . ln_Succ) -> Entry -> Header -> Name;
  1092.                             else
  1093.                                 CallingName = DialNode -> VanillaNode . ln_Succ -> ln_Name;
  1094.                         }
  1095.                         else
  1096.                             CallingName = "-";
  1097.                     }
  1098.  
  1099.                     PrintBox(Handle,GAD_CALLING,3,CallingName);
  1100.  
  1101.                         /* Right now we're dialing. */
  1102.  
  1103.                     PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_DIALING_TXT));
  1104.  
  1105.                         /* Build the dialing command. */
  1106.  
  1107.                     strcpy(DialBuffer,PrefixBuffer);
  1108.                     strcat(DialBuffer,NumberBuffer);
  1109.  
  1110.                     if(DialNode -> Entry)
  1111.                     {
  1112.                         if(DialNode -> Entry -> Config -> ModemConfig)
  1113.                             strcat(DialBuffer,DialNode -> Entry -> Config -> ModemConfig -> DialSuffix);
  1114.                         else
  1115.                             strcat(DialBuffer,Config -> ModemConfig -> DialSuffix);
  1116.                     }
  1117.                     else
  1118.                         strcat(DialBuffer,Config -> ModemConfig -> DialSuffix);
  1119.  
  1120.                         /* Pick up dial timeout and dial retries. */
  1121.  
  1122.                     if(DialNode -> Entry && DialNode -> Entry -> Config -> ModemConfig)
  1123.                     {
  1124.                         DialTimeout    = DialNode -> Entry -> Config -> ModemConfig -> DialTimeout;
  1125.                         DialRetries    = DialNode -> Entry -> Config -> ModemConfig -> DialRetries;
  1126.                     }
  1127.                     else
  1128.                     {
  1129.                         DialTimeout    = Config -> ModemConfig -> DialTimeout;
  1130.                         DialRetries    = Config -> ModemConfig -> DialRetries;
  1131.                     }
  1132.  
  1133.                         /* Dial the number. */
  1134.  
  1135.                     SerialCommand(DialBuffer);
  1136.  
  1137.                         /* Now we should be dialing. */
  1138.  
  1139.                     Calling = FALSE;
  1140.                     Dialing = TRUE;
  1141.  
  1142.                         /* For the sake of precision. */
  1143.  
  1144.                     RunCount = 0;
  1145.                 }
  1146.             }
  1147.  
  1148.                 /* Are we to skip the current assignment? */
  1149.  
  1150.             if(Skipping && !Done)
  1151.             {
  1152.                 Skipping = FALSE;
  1153.  
  1154.                     /* Are we currently dialing? */
  1155.  
  1156.                 if(Dialing)
  1157.                 {
  1158.                         /* Hang up if necessary. */
  1159.  
  1160.                     if(NeedHangUp)
  1161.                     {
  1162.                         BOOL UseHangUp;
  1163.  
  1164.                         if(DialNode -> Entry && DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  1165.                             UseHangUp = DialNode -> Entry -> Config -> ModemConfig -> AbortHangsUp;
  1166.                         else
  1167.                             UseHangUp = Config -> ModemConfig -> AbortHangsUp;
  1168.  
  1169.                         if(UseHangUp)
  1170.                             HangUp();
  1171.                         else
  1172.                         {
  1173.                             SerWrite("\r",1);
  1174.                             WaitTime(1,0);
  1175.                         }
  1176.                     }
  1177.                     else
  1178.                         NeedHangUp = TRUE;
  1179.  
  1180.                         /* Ignore the response of the modem. */
  1181.  
  1182.                     HandleSerial();
  1183.  
  1184.                     FlowInit(TRUE);
  1185.  
  1186.                         /* Did we dial all the numbers available? */
  1187.  
  1188.                     if(!NextNumber)
  1189.                     {
  1190.                             /* Is this one the last entry? */
  1191.  
  1192.                         if(DialNode -> VanillaNode . ln_Succ -> ln_Succ)
  1193.                         {
  1194.                             DialNode = (struct PhoneNode *)DialNode -> VanillaNode . ln_Succ;
  1195.  
  1196.                             Dialing = FALSE;
  1197.                             Calling = TRUE;
  1198.                         }
  1199.                         else
  1200.                         {
  1201.                                 /* Yet another dial attempt coming up. */
  1202.  
  1203.                             DialAttempt++;
  1204.  
  1205.                                 /* Is this one the last dial
  1206.                                  * attempt to be made?
  1207.                                  */
  1208.  
  1209.                             if(DialAttempt >= DialRetries && DialRetries >= 0)
  1210.                             {
  1211.                                 PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  1212.  
  1213.                                 WakeUp(PanelWindow,SOUND_BELL);
  1214.  
  1215.                                 WaitTime(2,0);
  1216.  
  1217.                                 Say(LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  1218.  
  1219.                                 Done = TRUE;
  1220.                             }
  1221.                             else
  1222.                             {
  1223.                                     /* Get the first list entry. */
  1224.  
  1225.                                 DialNode = (struct PhoneNode *)DialList -> lh_Head;
  1226.  
  1227.                                     /* Get the redial delay. */
  1228.  
  1229.                                 if(DialNode -> Entry)
  1230.                                 {
  1231.                                     if(DialNode -> Entry -> Config -> ModemConfig)
  1232.                                         RedialTimeout = DialNode -> Entry -> Config -> ModemConfig -> RedialDelay;
  1233.                                     else
  1234.                                         RedialTimeout = Config -> ModemConfig -> RedialDelay;
  1235.                                 }
  1236.                                 else
  1237.                                     RedialTimeout = Config -> ModemConfig -> RedialDelay;
  1238.  
  1239.                                     /* No redial delay? Restart dialing... */
  1240.  
  1241.                                 if(!RedialTimeout)
  1242.                                 {
  1243.                                     Dialing = FALSE;
  1244.                                     Calling = TRUE;
  1245.  
  1246.                                     WaitTime(1,0);
  1247.                                 }
  1248.                                 else
  1249.                                 {
  1250.                                         /* Go into redial delay. */
  1251.  
  1252.                                     PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_REDIAL_DELAY_TXT));
  1253.  
  1254.                                     Dialing = FALSE;
  1255.                                     Waiting = TRUE;
  1256.  
  1257.                                         /* For the sake of precision. */
  1258.  
  1259.                                     RunCount = 0;
  1260.  
  1261.                                     Say(LocaleString(MSG_DIALPANEL_WAITING_TXT));
  1262.  
  1263.                                         /* No entry is currently being called. */
  1264.  
  1265.                                     PrintBox(Handle,GAD_CALLING,0,"-");
  1266.                                     PrintBox(Handle,GAD_CALLING,1,"-");
  1267.                                     PrintBox(Handle,GAD_CALLING,2,"-");
  1268.  
  1269.                                     LT_SetAttributes(Handle,GAD_REMOVE,
  1270.                                         GA_Disabled,    TRUE,
  1271.                                     TAG_DONE);
  1272.  
  1273.                                         /* Display name of entry to call next. */
  1274.  
  1275.                                     if(DialNode -> Entry)
  1276.                                         PrintBox(Handle,GAD_CALLING,3,DialNode -> Entry -> Header -> Name);
  1277.                                     else
  1278.                                         PrintBox(Handle,GAD_CALLING,3,LocaleString(MSG_GLOBAL_UNKNOWN_TXT));
  1279.                                 }
  1280.                             }
  1281.                         }
  1282.                     }
  1283.                     else
  1284.                     {
  1285.                         Dialing = FALSE;
  1286.                         Calling = TRUE;
  1287.                     }
  1288.                 }
  1289.                 else
  1290.                 {
  1291.                         /* Stop waiting. */
  1292.  
  1293.                     if(Waiting)
  1294.                     {
  1295.                         LT_SetAttributes(Handle,GAD_REMOVE,
  1296.                             GA_Disabled,    FALSE,
  1297.                         TAG_DONE);
  1298.  
  1299.                         Waiting = FALSE;
  1300.                         Calling = TRUE;
  1301.  
  1302.                             /* Restart dialing. */
  1303.  
  1304.                         DialNode = (struct PhoneNode *)DialList -> lh_Head;
  1305.  
  1306.                         NextNumber = NULL;
  1307.                     }
  1308.                 }
  1309.             }
  1310.  
  1311.                 /* Take care of serial input. */
  1312.  
  1313.             if(!Done)
  1314.                 HandleSerial();
  1315.  
  1316.                 /* Any news from the modem? */
  1317.  
  1318.             if(!Done && FlowInfo . Changed)
  1319.             {
  1320.                     /* Current number is busy. */
  1321.  
  1322.                 if(FlowInfo . Busy || (FlowInfo . NoCarrier && Config -> ModemConfig -> NoCarrierIsBusy))
  1323.                 {
  1324.                     FlowInit(TRUE);
  1325.  
  1326.                     if(Dialing && !Done)
  1327.                     {
  1328.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_LINE_IS_BUSY_TXT));
  1329.  
  1330.                         Say(LocaleString(MSG_DIALPANEL_LINE_IS_BUSY_TXT));
  1331.  
  1332.                         WaitTime(1,0);
  1333.  
  1334.                         Skipping = TRUE;
  1335.  
  1336.                         NeedHangUp = FALSE;
  1337.                     }
  1338.                 }
  1339.  
  1340.                     /* Line does not feature a dialtone. */
  1341.  
  1342.                 if(FlowInfo . NoDialTone)
  1343.                 {
  1344.                     FlowInit(TRUE);
  1345.  
  1346.                     if(Dialing && !Done)
  1347.                     {
  1348.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_NO_DIALTONE_TXT));
  1349.  
  1350.                         WakeUp(PanelWindow,SOUND_ERROR);
  1351.  
  1352.                         Say(LocaleString(MSG_DIALPANEL_NO_DIALTONE_TXT));
  1353.  
  1354.                         Error = Done = TRUE;
  1355.                     }
  1356.                 }
  1357.  
  1358.                     /* Somebody tries to call us. */
  1359.  
  1360.                 if(FlowInfo . Ring)
  1361.                 {
  1362.                     FlowInit(TRUE);
  1363.  
  1364.                     if(!Done)
  1365.                     {
  1366.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_GLOBAL_INCOMING_CALL_TXT));
  1367.  
  1368.                         WakeUp(PanelWindow,SOUND_RING);
  1369.  
  1370.                         Say(LocaleString(MSG_GLOBAL_INCOMING_CALL_TXT));
  1371.  
  1372.                         Error = Done = TRUE;
  1373.                     }
  1374.                 }
  1375.  
  1376.                     /* Somebody's talking. */
  1377.  
  1378.                 if(FlowInfo . Voice)
  1379.                 {
  1380.                     FlowInit(TRUE);
  1381.  
  1382.                     if(!Done)
  1383.                     {
  1384.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_INCOMING_VOICE_CALL_TXT));
  1385.  
  1386.                         WakeUp(PanelWindow,SOUND_VOICE);
  1387.  
  1388.                         Say(LocaleString(MSG_DIALPANEL_INCOMING_VOICE_CALL_TXT));
  1389.  
  1390.                         Error = Done = TRUE;
  1391.                     }
  1392.                 }
  1393.  
  1394.                     /* We got a connect. */
  1395.  
  1396.                 if(FlowInfo . Connect)
  1397.                 {
  1398.                     FlowInit(TRUE);
  1399.  
  1400.                     if(Dialing && !Done)
  1401.                     {
  1402.                             /* Make the connection. */
  1403.  
  1404.                         Connect(DialNode,NumberBuffer);
  1405.  
  1406.                         Done = TRUE;
  1407.  
  1408.                             /* Wake the user up. */
  1409.  
  1410.                         if(BaudBuffer[0])
  1411.                         {
  1412.                             PrintBox(Handle,GAD_NOTE,0,"CONNECT %s",BaudBuffer);
  1413.  
  1414.                             WakeUp(PanelWindow,SOUND_CONNECT);
  1415.  
  1416.                             WaitTime(2,0);
  1417.  
  1418.                                 /* Install new baud rate if desired. */
  1419.  
  1420.                             if(Config -> ModemConfig -> ConnectAutoBaud && DTERate > 110)
  1421.                             {
  1422.                                 Config -> SerialConfig -> BaudRate = DTERate;
  1423.  
  1424.                                 ReconfigureSerial(PanelWindow,NULL);
  1425.                             }
  1426.                         }
  1427.                         else
  1428.                         {
  1429.                             PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_CONNECTION_ESTABLISHED_TXT));
  1430.  
  1431.                             WakeUp(PanelWindow,SOUND_CONNECT);
  1432.                         }
  1433.  
  1434.                         Say(LocaleString(MSG_DIALPANEL_CONNECTION_ESTABLISHED_TXT));
  1435.                     }
  1436.                 }
  1437.  
  1438.                     /* Looks like an error. */
  1439.  
  1440.                 if(FlowInfo . Error)
  1441.                 {
  1442.                     FlowInit(TRUE);
  1443.  
  1444.                     if(Dialing && !Done)
  1445.                     {
  1446.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  1447.  
  1448.                         WakeUp(PanelWindow,SOUND_ERROR);
  1449.  
  1450.                         Error = Done = TRUE;
  1451.                     }
  1452.                 }
  1453.             }
  1454.  
  1455.                 /* If nothing special's up... */
  1456.  
  1457.             if(!Done && !Skipping && (Dialing || Waiting))
  1458.             {
  1459.                     /* Wait half a second. */
  1460.  
  1461.                 WaitTime(0,MILLION / 2);
  1462.  
  1463.                 if(Dialing)
  1464.                 {
  1465.                     PrintBox(Handle,GAD_TIME,0,"%2ld:%02ld",DialTimeout / 60,DialTimeout % 60);
  1466.  
  1467.                     if(DialRetries < 0)
  1468.                         PrintBox(Handle,GAD_TIME,1,LocaleString(MSG_DIAL_RETRIES_UNLIMITED_TXT));
  1469.                     else
  1470.                         PrintBox(Handle,GAD_TIME,1,LocaleString(MSG_DIALPANEL_ATTEMPT_OF_TXT),DialAttempt + 1,DialRetries);
  1471.                 }
  1472.  
  1473.                 if(Waiting)
  1474.                     PrintBox(Handle,GAD_TIME,0,"%2ld:%02ld",RedialTimeout / 60,RedialTimeout % 60);
  1475.  
  1476.                     /* The following instructions are executed each second */
  1477.  
  1478.                 if(RunCount++)
  1479.                 {
  1480.                     RunCount = 0;
  1481.  
  1482.                         /* Are we dialing? */
  1483.  
  1484.                     if(Dialing)
  1485.                     {
  1486.                             /* Yet another second has elapsed. */
  1487.  
  1488.                         if(DialTimeout > 0)
  1489.                             DialTimeout--;
  1490.  
  1491.                             /* Has the dial timeout elapsed without
  1492.                              * a connection being made?
  1493.                              */
  1494.  
  1495.                         if(!DialTimeout)
  1496.                         {
  1497.                             PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_DIAL_ATTEMPT_TIMEOUT_TXT));
  1498.  
  1499.                             Skipping = TRUE;
  1500.                         }
  1501.                     }
  1502.  
  1503.                         /* Are we waiting? */
  1504.  
  1505.                     if(Waiting)
  1506.                     {
  1507.                             /* Yet another second has elapsed. */
  1508.  
  1509.                         if(RedialTimeout > 0)
  1510.                             RedialTimeout--;
  1511.  
  1512.                             /* The redial delay has elapsed,
  1513.                              * start dialing again.
  1514.                              */
  1515.  
  1516.                         if(!RedialTimeout)
  1517.                             Skipping = TRUE;
  1518.                     }
  1519.                 }
  1520.             }
  1521.         }
  1522.         while(!Done);
  1523.  
  1524.             /* Are we online or not? */
  1525.  
  1526.         ObtainSemaphore(&OnlineSemaphore);
  1527.  
  1528.         if(!Online)
  1529.         {
  1530.             ReleaseSemaphore(&OnlineSemaphore);
  1531.  
  1532.                 /* Is the serial setup different? */
  1533.  
  1534.             if(memcmp(Config -> SerialConfig,&OriginalSerialConfig,sizeof(struct SerialSettings)))
  1535.             {
  1536.                     /* Set up the old serial configuration. */
  1537.  
  1538.                 if(ReconfigureSerial(PanelWindow,&OriginalSerialConfig) != RECONFIGURE_FAILURE)
  1539.                 {
  1540.                         /* Send the exit command if necessary. */
  1541.  
  1542.                     if(ExitCommand[0])
  1543.                     {
  1544.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_SENDING_MODEM_EXIT_COMMAND_TXT));
  1545.  
  1546.                         FlowInit(TRUE);
  1547.  
  1548.                         SerialCommand(ExitCommand);
  1549.  
  1550.                         WaitTime(1,0);
  1551.  
  1552.                         HandleSerial();
  1553.  
  1554.                         if(FlowInfo . Changed && FlowInfo . Error)
  1555.                         {
  1556.                             PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  1557.  
  1558.                             WakeUp(PanelWindow,SOUND_ERROR);
  1559.  
  1560.                             Error = TRUE;
  1561.                         }
  1562.                     }
  1563.  
  1564.                         /* Take care of the init command if necessary. */
  1565.  
  1566.                     if(Config -> ModemConfig -> ModemInit[0] && !Error)
  1567.                     {
  1568.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_SENDING_MODEM_INIT_COMMAND_TXT));
  1569.  
  1570.                         FlowInit(TRUE);
  1571.  
  1572.                         SerialCommand(Config -> ModemConfig -> ModemInit);
  1573.  
  1574.                         WaitTime(1,0);
  1575.  
  1576.                         HandleSerial();
  1577.  
  1578.                         if(FlowInfo . Changed && FlowInfo . Error)
  1579.                         {
  1580.                             PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  1581.  
  1582.                             WakeUp(PanelWindow,SOUND_ERROR);
  1583.  
  1584.                             Error = TRUE;
  1585.                         }
  1586.                     }
  1587.                 }
  1588.             }
  1589.         }
  1590.         else
  1591.             ReleaseSemaphore(&OnlineSemaphore);
  1592.  
  1593.             /* Make sure the error gets displayed. */
  1594.  
  1595.         if(Error)
  1596.         {
  1597.             struct IntuiMessage    *Msg;
  1598.             ULONG                 MsgClass;
  1599.             WORD                 i;
  1600.  
  1601.             for(i = GAD_SKIP ; i <= GAD_REMOVE ; i++)
  1602.                 LT_SetAttributes(Handle,i,GA_Disabled,TRUE,TAG_DONE);
  1603.  
  1604.             Done = FALSE;
  1605.  
  1606.             do
  1607.             {
  1608.                 if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  1609.                     break;
  1610.  
  1611.                 while(Msg = LT_GetIMsg(Handle))
  1612.                 {
  1613.                     MsgClass = Msg -> Class;
  1614.  
  1615.                     LT_ReplyIMsg(Msg);
  1616.  
  1617.                     if(MsgClass == IDCMP_CLOSEWINDOW || MsgClass == IDCMP_GADGETUP)
  1618.                         Done = TRUE;
  1619.                 }
  1620.             }
  1621.             while(!Done);
  1622.         }
  1623.  
  1624.         PopWindow();
  1625.  
  1626.         LT_DeleteHandle(Handle);
  1627.  
  1628.             /* Reset the scanner. */
  1629.  
  1630.         FullCheck = FALSE;
  1631.  
  1632.         FlowInit(TRUE);
  1633.  
  1634.             /* We are done now, restart echoing serial */
  1635.  
  1636.         Quiet = FALSE;
  1637.  
  1638.         ReleaseWindows();
  1639.  
  1640.             /* Reset the display if necessary. */
  1641.  
  1642.         if(ResetDisplay)
  1643.         {
  1644.             if(!DisplayReset())
  1645.                 return(FALSE);
  1646.         }
  1647.  
  1648.             /* Handle online jobs. */
  1649.  
  1650.         ObtainSemaphore(&OnlineSemaphore);
  1651.  
  1652.         if(Online)
  1653.         {
  1654.             ReleaseSemaphore(&OnlineSemaphore);
  1655.  
  1656.             SetDialMenu(FALSE);
  1657.  
  1658.                 /* Send the startup macro if necessary. */
  1659.  
  1660.             if(SendStartup)
  1661.             {
  1662.                 if(Config -> CommandConfig -> LoginMacro[0])
  1663.                     SerialCommand(Config -> CommandConfig -> LoginMacro);
  1664.  
  1665.                 if(Config -> CommandConfig -> StartupMacro[0])
  1666.                     SerialCommand(Config -> CommandConfig -> StartupMacro);
  1667.  
  1668.                 SendStartup = FALSE;
  1669.             }
  1670.  
  1671.                 /* Take care of the recording feature. */
  1672.  
  1673.             if(Record)
  1674.             {
  1675.                 if(CreateRecord(CurrentBBSName[0] ? CurrentBBSName : CurrentBBSNumber))
  1676.                 {
  1677.                     RememberResetOutput();
  1678.                     RememberResetInput();
  1679.  
  1680.                     RememberOutput = TRUE;
  1681.  
  1682.                     Recording = TRUE;
  1683.                     RecordingLine = FALSE;
  1684.  
  1685.                     OnItem(MEN_RECORD_LINE);
  1686.  
  1687.                     CheckItem(MEN_RECORD,TRUE);
  1688.                     CheckItem(MEN_RECORD_LINE,FALSE);
  1689.                 }
  1690.             }
  1691.         }
  1692.         else
  1693.         {
  1694.             ReleaseSemaphore(&OnlineSemaphore);
  1695.  
  1696.             SetDialMenu(TRUE);
  1697.         }
  1698.     }
  1699.     else
  1700.         ReleaseWindows();
  1701.  
  1702.         /* Reply to the message that started the
  1703.          * dialing process.
  1704.          */
  1705.  
  1706.     ObtainSemaphore(&OnlineSemaphore);
  1707.  
  1708.     Forbid();
  1709.  
  1710.     if(DialMsg)
  1711.     {
  1712.         if(Online)
  1713.             DialMsg -> rm_Result1 = RC_OK;
  1714.         else
  1715.             DialMsg -> rm_Result1 = RC_WARN;
  1716.  
  1717.         DialMsg -> rm_Result2 = 0;
  1718.  
  1719.         ReplyMsg(DialMsg);
  1720.  
  1721.         DialMsg = NULL;
  1722.     }
  1723.  
  1724.     Permit();
  1725.  
  1726.     ReleaseSemaphore(&OnlineSemaphore);
  1727.  
  1728.     return(Result);
  1729. }
  1730.